package com.lab.book.web.config;

import com.lab.book.web.interceptor.AuthorityInterceptor;
import com.lab.book.web.interceptor.LoginInterceptor;
//import com.lab.book.web.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebConfigurer implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/pic/view/**").addResourceLocations("file:/D:/www/lady/ROOT/");
		registry.addResourceHandler("/video/view/**").addResourceLocations("file:/D:/www/movie/ROOT/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截所有请求，通过判断是否有 @LoginRequired 注解 决定是否需要登录
        //registry.addInterceptor(LoginInterceptor()).addPathPatterns("/**");
        //registry.addInterceptor(AuthorityInterceptor()).addPathPatterns("/**");
        /**
        InterceptorRegistration registration = registry.addInterceptor(TokenInterceptor());

        registration.excludePathPatterns("/login");
        registration.excludePathPatterns("/loginOut");
        registration.excludePathPatterns("/register");
        registration.excludePathPatterns("/error");
        registration.excludePathPatterns("/actuator/**");
        registration.excludePathPatterns("/monitor/**");

        registration.addPathPatterns("/**");
        */
    }

    @Bean
    public LoginInterceptor LoginInterceptor() {
        return new LoginInterceptor();
    }

    @Bean
    public AuthorityInterceptor AuthorityInterceptor() {
        return new AuthorityInterceptor();
    }
    /**
    @Bean
    public TokenInterceptor TokenInterceptor() {
        return new TokenInterceptor();
    }
    */
}
